package top.yxf.spring.support;

import top.yxf.spring.BeansException;
import top.yxf.spring.config.BeanDefinition;

import java.util.HashMap;
import java.util.Map;

/**
 * @author xs.wu
 */
public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFactory implements BeanDefinitionRegistry {

    private final Map<String, BeanDefinition> map = new HashMap<>();

    @Override
    public void registerBeanDefinition(String beanName, BeanDefinition beanDefinition) {
        map.put(beanName, beanDefinition);
    }

    @Override
    protected BeanDefinition getBeanDefinition(String name) throws BeansException {
        BeanDefinition beanDefinition = map.get(name);
        if (beanDefinition == null) {
            throw new BeansException("no bean named" + name + "is defined");
        }
        return beanDefinition;
    }
}
